import { isEmpty, isObject } from "lodash-es";

/**
 * 枚举转值
 * @param obj
 */
export function enum2Value(obj: any) {
  if (isObject(obj)) {
    Object.keys(obj).forEach(key => {
      if (!isEmpty(obj[key])) {
        if (
          // eslint-disable-next-line no-prototype-builtins
          obj[key].hasOwnProperty("value") &&
          // eslint-disable-next-line no-prototype-builtins
          obj[key].hasOwnProperty("label")
        ) {
          obj[key] = obj[key].value;
        }
      }
    });
  }

  return obj;
}

/**
 * 转image对象
 * @param imageId
 * @param imageUrl
 */
export function toImage(imageId?: number, imageUrl?: string) {
  if (imageId != undefined && imageId > 0 && imageUrl != undefined && imageUrl != "") {
    return {
      fileId: imageId,
      url: imageUrl
    };
  }

  return null;
}
